﻿#ifndef GLOBALDEF_H
#define GLOBALDEF_H
#include <QString>
#include <QDebug>
#include <QFile>
#include <QApplication>

#include <QtCore/qglobal.h>
#include <stdio.h>

#ifdef PAGEFRAME_LIB
# define PAGEFRAME_EXPORT Q_DECL_EXPORT
#else
# define PAGEFRAME_EXPORT Q_DECL_IMPORT
#endif

namespace GlobalSpace
{
    const QString BLACK_QSS_FILE_PATH = ":/res/res/stylesheet/black.qss";
    const QString LOGO_PATH = ":/res/res/image/image.png";

    const int INT_DOUBLE_TIMES = 2;
    const float FLOAT_DOUBLE_TIMES = 2.0f;

    // 加载皮肤
    inline bool LoadQss(const QString& qssFile)
    {
        QFile file(qssFile);
        file.open(QFile::ReadOnly);
        if(!file.isOpen())
        {
            return false;
        }

        qApp->setStyleSheet(file.readAll());
        file.close();

        return true;
    }

    // 根据控件位置获取控件中心点位置
    inline QPoint GetCenterPosition(const QWidget *controlWidget)
    {
        QPoint centerPos;
        if(nullptr != controlWidget)
        {
            centerPos.setX(controlWidget->x() + controlWidget->width() / INT_DOUBLE_TIMES);
            centerPos.setY(controlWidget->y() + controlWidget->height() / INT_DOUBLE_TIMES);
        }
        return centerPos;
    }

    // 获取控件中心点位置
    inline QPointF GetCenterPoint(const QWidget *controlWidget)
    {
        QPointF centerPoint;
        if(nullptr != controlWidget)
        {
            centerPoint.setX(controlWidget->width() / FLOAT_DOUBLE_TIMES);
            centerPoint.setY(controlWidget->height() / FLOAT_DOUBLE_TIMES);
        }
        return centerPoint;
    }

    // 获取图片中心点位置
    inline QPointF GetCenterPoint(const QImage &image)
    {
        QPointF centerPoint;
        centerPoint.setX(image.width() / FLOAT_DOUBLE_TIMES);
        centerPoint.setY(image.height() / FLOAT_DOUBLE_TIMES);
        return centerPoint;
    }

} // namespace GlobalSpace

#endif // GLOBALDEF_H
